﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.DataAnnotations;
using System.Xml.Serialization;
using System.ComponentModel;

namespace ViewMaker.Core.Controls
{
    /// <summary>
    /// リテラルViewコントロール
    /// </summary>
    public class LiteralViewControl : HeaderViewControl
    {
        public new class Properties : HeaderViewControl.Properties
        {
            public const string Literal = "Literal";
        }

        /// <summary>
        /// リテラルタグ
        /// </summary>
        [ViewProperty(TextBoxViewControl.Properties.Height, 100)]
        [ViewProperty(TextBoxViewControl.Properties.IsMultiline, true)]
        public string Literal { get; set; }

        [XmlIgnore]
        [Browsable(false)]
        public override bool CanAddChild { get { return true; } }

        public LiteralViewControl()
        {
            ControlType = ViewControlType.Literal;
            this.IsPanel = true;
        }

        public override List<XamlNode> CreateXaml(XamlNode parent)
        {
            var list = base.CreateXaml(parent);
            if (!string.IsNullOrEmpty(Literal))
            {
                var xaml = parent.ParseElement(Literal);

                foreach (var child in Item.Children)
                {
                    foreach (var item in child.CreateXaml(xaml))
                    {
                        xaml.AppendChild(item);
                    }
                }
                ApplyBaseProperty(xaml);
                list.Add(xaml);
            }
            return list;
        }
    }

}
